package com.itfreer.arcgis.edit;

import com.esri.arcgisruntime.layers.FeatureLayer;
import com.itfreer.arcgis.draw.DrawCommand;
import com.itfreer.arcgis.draw.DrawToolManager;
import com.itfreer.arcgis.utils.FeatureTableUtils;
import com.itfreer.utils.common.ToastUtils;
import com.itfreer.utils.config.ConfigManager;

import java.util.Map;

public class SplitSelectFeatureCommand implements DrawCommand
{
    @Override
    public void Execute(Map<String,Object> params)
    {
        if (DrawToolManager.GetCurrentTool() == null) {
            ToastUtils.showShort(ConfigManager.getContext(), "当前无编辑操作！");
            return;
        }
        FeatureLayer featureLayer = EditToolUtils.getCurrentEditFeatureLayer();
        if (featureLayer != null)
        {
            if (FeatureTableUtils.isPolygonFeatuerTable(featureLayer.getFeatureTable()))
            {
                SplitSelectPolygonFeatureCommand command = new SplitSelectPolygonFeatureCommand();
                command.Execute(null);
            }
            else if (FeatureTableUtils.isPolylineFeatuerTable(featureLayer.getFeatureTable()))
            {
                SplitSelectPolylineFeatureCommand command = new SplitSelectPolylineFeatureCommand();
                command.Execute(null);
            }
            else
            {
                ToastUtils.showShort(ConfigManager.getContext(), "当前图层无法进行分割操作");
                return;
            }
        }
        else
        {
            ToastUtils.showShort(ConfigManager.getContext(), "当前无可编辑图层");
        }
    }
}